<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header(用户数据源添加)" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-add" name="form-config-add" >
        <h4 class="form-header h4">用户数据源添加</h4>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据源名称：</label>
                    <div class="col-sm-8">
                        <input id="dataSourceName" name="dataSourceName" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据库地址：</label>
                    <div class="col-sm-8">
                        <input id="dataUrl" name="dataUrl" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据库端口：</label>
                    <div class="col-sm-8">
                        <input id="dataPort" name="dataPort" class="form-control" type="text"  required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据库/ODBC：</label>
                    <div class="col-sm-8">
                        <input id="dataOdbc" name="dataOdbc" class="form-control" type="text"  required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据库用户名：</label>
                    <div class="col-sm-8">
                        <input id="dataUser" name="dataUser" class="form-control" type="text"  required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">数据库密码：</label>
                    <div class="col-sm-8">
                        <input id="dataPassword" name="dataPassword" class="form-control" type="text"  required>
                    </div>
                </div>
            </div>
        </div>



    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "system/userDataSource";

    $("#form-config-add").validate({
        onkeyup: false,
        onSubmit: true,
        rules: {
            dataSourceName: {
                remote: {
                    url: prefix + "/checkDataSourceNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "typeName": function() {
                            return $.common.trim($("#dataSourceName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return data;
                    }
                }
            }
        },
        messages: {
            "dataSourceName": {
                remote: "该数据源名称已存在"
            }
        },
        focusCleanup: true
    });


    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData($('#form-config-add')[0]);
            // formData.append('file', $('#file')[0].files[0]);

            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }
</script>
</div>
</body>

</html>
